//SPDX-FileCopyrightText: Copyright 2022-2024 深圳市同心圆网络有限公司
//SPDX-License-Identifier: GPL-3.0-only

package utils

import (
	"context"
	"errors"

	"atomgit.com/openlinksaas-org/api-server/dao/project_dao"
)

var ErrNoProject = errors.New("no project")
var ErrNoRole = errors.New("no member role")

func GetProjectMemberRole(ctx context.Context, projectId, memberUserId string) (*project_dao.ProjectInfoDbItem, *project_dao.MemberInfoDbItem, *project_dao.RoleInfoDbItem, error) {
	projectItem, err := project_dao.ProjectInfoDao.Get(ctx, projectId)
	if err != nil {
		return nil, nil, nil, ErrNoProject
	}
	memberItem, err := project_dao.MemberInfoDao.Get(ctx, projectId, memberUserId)
	if err != nil {
		return projectItem, memberItem, nil, ErrNoRole
	}
	roleItem, err := project_dao.MemberRoleDao.Get(ctx, projectId, memberItem.RoleId)
	if err != nil {
		return projectItem, memberItem, nil, ErrNoRole
	}
	return projectItem, memberItem, roleItem, nil
}
